import Immutable from 'immutable';

const defaultState = new Immutable.List();

export default function demoReducer(state = defaultState, action) {
  switch(action.type) {
    case 'CREATE_DEMO_DATA':
      return state.concat(action.data);
    case 'EDIT_DEMO_DATA':
      state.map(function(item) {
        if (item.id == action.id) {
          item.name = action.data.name,
          item.phone = action.data.phone
        }
      })
      return state;
    case 'DELETE_DEMO_DATA':
      state = _.remove(state, function(data) {
        return action.id !== data.id
      })
      return state;
    case 'LOAD_DEMO_DATA':
      return action.data.data;
    default:
      return state;
  }
}
